<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;

class Integral extends Controller{

    public function addIntegral(){
        $data=input();
        $user_username=$data['user_username'];
        unset($data['user_username']);
        $data['user_id']=Db::name("user")->where("user_username",$user_username)->value("user_id");
        if(Db::name("integral")->insert($data))
            return ['status'=>1,'message'=>'操作成功'];
        else
            return ['status'=>0,'message'=>'操作失败'];
    }

    public function getUserIntegral(){
        $user_username=input('user_username');
        $user_id=Db::name("user")->where("user_username",$user_username)->value("user_id");
        $userIntegral=Db::name("integral")->where("user_username",$user_username)->sum("integral_value");
        return ['status'=>1,'message'=>'获取成功','userIntegral'=>$userIntegral];
    }
}